//
//  FinderDetailModel.m
//
//  Created by   on 2019/6/4
//  Copyright (c) 2019 __MyCompanyName__. All rights reserved.
//

#import "FinderDetailModel.h"


NSString *const kFinderDetailModelId = @"id";
NSString *const kFinderDetailModelTopCount = @"topCount";
NSString *const kFinderDetailModelArticleContet = @"articleContet";
NSString *const kFinderDetailModelUpdateTime = @"updateTime";
NSString *const kFinderDetailModelDelete = @"delete";
NSString *const kFinderDetailModelIsDelete = @"isDelete";
NSString *const kFinderDetailModelCollectionCount = @"collectionCount";
NSString *const kFinderDetailModelAddUser = @"addUser";
NSString *const kFinderDetailModelArticleType = @"articleType";
NSString *const kFinderDetailModelAddTime = @"addTime";
NSString *const kFinderDetailModelUpdateUser = @"updateUser";
NSString *const kFinderDetailModelSmallImage = @"smallImage";
NSString *const kFinderDetailModelArticleTitle = @"articleTitle";
NSString *const kFinderDetailModelArticleStatus = @"articleStatus";
NSString *const kFinderDetailModelTop = @"top";
NSString *const kFinderDetailModelLike = @"like";

@interface FinderDetailModel ()

- (id)objectOrNilForKey:(id)aKey fromDictionary:(NSDictionary *)dict;

@end

@implementation FinderDetailModel

@synthesize internalBaseClassIdentifier = _internalBaseClassIdentifier;
@synthesize topCount = _topCount;
@synthesize articleContet = _articleContet;
@synthesize updateTime = _updateTime;
@synthesize delete = _delete;
@synthesize isDelete = _isDelete;
@synthesize collectionCount = _collectionCount;
@synthesize addUser = _addUser;
@synthesize articleType = _articleType;
@synthesize addTime = _addTime;
@synthesize updateUser = _updateUser;
@synthesize smallImage = _smallImage;
@synthesize articleTitle = _articleTitle;
@synthesize articleStatus = _articleStatus;
@synthesize top = _top;
@synthesize like = _like;


+ (instancetype)modelObjectWithDictionary:(NSDictionary *)dict
{
    return [[self alloc] initWithDictionary:dict];
}

- (instancetype)initWithDictionary:(NSDictionary *)dict
{
    self = [super init];
    
    // This check serves to make sure that a non-NSDictionary object
    // passed into the model class doesn't break the parsing.
    if(self && [dict isKindOfClass:[NSDictionary class]]) {
            self.internalBaseClassIdentifier = [[self objectOrNilForKey:kFinderDetailModelId fromDictionary:dict] doubleValue];
            self.topCount = [[self objectOrNilForKey:kFinderDetailModelTopCount fromDictionary:dict] doubleValue];
            self.articleContet = [self objectOrNilForKey:kFinderDetailModelArticleContet fromDictionary:dict];
            self.updateTime = [[self objectOrNilForKey:kFinderDetailModelUpdateTime fromDictionary:dict] doubleValue];
            self.delete = [[self objectOrNilForKey:kFinderDetailModelDelete fromDictionary:dict] boolValue];
            self.isDelete = [[self objectOrNilForKey:kFinderDetailModelIsDelete fromDictionary:dict] boolValue];
            self.collectionCount = [[self objectOrNilForKey:kFinderDetailModelCollectionCount fromDictionary:dict] doubleValue];
            self.addUser = [self objectOrNilForKey:kFinderDetailModelAddUser fromDictionary:dict];
            self.articleType = [self objectOrNilForKey:kFinderDetailModelArticleType fromDictionary:dict];
            self.addTime = [[self objectOrNilForKey:kFinderDetailModelAddTime fromDictionary:dict] doubleValue];
            self.updateUser = [self objectOrNilForKey:kFinderDetailModelUpdateUser fromDictionary:dict];
            self.smallImage = [self objectOrNilForKey:kFinderDetailModelSmallImage fromDictionary:dict];
            self.articleTitle = [self objectOrNilForKey:kFinderDetailModelArticleTitle fromDictionary:dict];
            self.articleStatus = [[self objectOrNilForKey:kFinderDetailModelArticleStatus fromDictionary:dict] boolValue];
        self.top = [[self objectOrNilForKey:kFinderDetailModelTop fromDictionary:dict] boolValue];
        self.like = [[self objectOrNilForKey:kFinderDetailModelLike fromDictionary:dict] boolValue];

    }
    
    return self;
    
}

- (NSDictionary *)dictionaryRepresentation
{
    NSMutableDictionary *mutableDict = [NSMutableDictionary dictionary];
    [mutableDict setValue:[NSNumber numberWithDouble:self.internalBaseClassIdentifier] forKey:kFinderDetailModelId];
    [mutableDict setValue:[NSNumber numberWithDouble:self.topCount] forKey:kFinderDetailModelTopCount];
    [mutableDict setValue:self.articleContet forKey:kFinderDetailModelArticleContet];
    [mutableDict setValue:[NSNumber numberWithDouble:self.updateTime] forKey:kFinderDetailModelUpdateTime];
    [mutableDict setValue:[NSNumber numberWithBool:self.delete] forKey:kFinderDetailModelDelete];
    [mutableDict setValue:[NSNumber numberWithBool:self.isDelete] forKey:kFinderDetailModelIsDelete];
    [mutableDict setValue:[NSNumber numberWithDouble:self.collectionCount] forKey:kFinderDetailModelCollectionCount];
    [mutableDict setValue:self.addUser forKey:kFinderDetailModelAddUser];
    [mutableDict setValue:self.articleType forKey:kFinderDetailModelArticleType];
    [mutableDict setValue:[NSNumber numberWithDouble:self.addTime] forKey:kFinderDetailModelAddTime];
    [mutableDict setValue:self.updateUser forKey:kFinderDetailModelUpdateUser];
    [mutableDict setValue:self.smallImage forKey:kFinderDetailModelSmallImage];
    [mutableDict setValue:self.articleTitle forKey:kFinderDetailModelArticleTitle];
    [mutableDict setValue:[NSNumber numberWithBool:self.articleStatus] forKey:kFinderDetailModelArticleStatus];
    [mutableDict setValue:[NSNumber numberWithBool:self.top] forKey:kFinderDetailModelTop];
    [mutableDict setValue:[NSNumber numberWithBool:self.like] forKey:kFinderDetailModelLike];

    return [NSDictionary dictionaryWithDictionary:mutableDict];
}

- (NSString *)description 
{
    return [NSString stringWithFormat:@"%@", [self dictionaryRepresentation]];
}

#pragma mark - Helper Method
- (id)objectOrNilForKey:(id)aKey fromDictionary:(NSDictionary *)dict
{
    id object = [dict objectForKey:aKey];
    return [object isEqual:[NSNull null]] ? nil : object;
}


#pragma mark - NSCoding Methods

- (id)initWithCoder:(NSCoder *)aDecoder
{
    self = [super init];

    self.internalBaseClassIdentifier = [aDecoder decodeDoubleForKey:kFinderDetailModelId];
    self.topCount = [aDecoder decodeDoubleForKey:kFinderDetailModelTopCount];
    self.articleContet = [aDecoder decodeObjectForKey:kFinderDetailModelArticleContet];
    self.updateTime = [aDecoder decodeDoubleForKey:kFinderDetailModelUpdateTime];
    self.delete = [aDecoder decodeBoolForKey:kFinderDetailModelDelete];
    self.isDelete = [aDecoder decodeBoolForKey:kFinderDetailModelIsDelete];
    self.collectionCount = [aDecoder decodeDoubleForKey:kFinderDetailModelCollectionCount];
    self.addUser = [aDecoder decodeObjectForKey:kFinderDetailModelAddUser];
    self.articleType = [aDecoder decodeObjectForKey:kFinderDetailModelArticleType];
    self.addTime = [aDecoder decodeDoubleForKey:kFinderDetailModelAddTime];
    self.updateUser = [aDecoder decodeObjectForKey:kFinderDetailModelUpdateUser];
    self.smallImage = [aDecoder decodeObjectForKey:kFinderDetailModelSmallImage];
    self.articleTitle = [aDecoder decodeObjectForKey:kFinderDetailModelArticleTitle];
    self.articleStatus = [aDecoder decodeBoolForKey:kFinderDetailModelArticleStatus];
    self.top = [aDecoder decodeBoolForKey:kFinderDetailModelTop];
    self.like = [aDecoder decodeBoolForKey:kFinderDetailModelLike];
    return self;
}

- (void)encodeWithCoder:(NSCoder *)aCoder
{

    [aCoder encodeDouble:_internalBaseClassIdentifier forKey:kFinderDetailModelId];
    [aCoder encodeDouble:_topCount forKey:kFinderDetailModelTopCount];
    [aCoder encodeObject:_articleContet forKey:kFinderDetailModelArticleContet];
    [aCoder encodeDouble:_updateTime forKey:kFinderDetailModelUpdateTime];
    [aCoder encodeBool:_delete forKey:kFinderDetailModelDelete];
    [aCoder encodeBool:_isDelete forKey:kFinderDetailModelIsDelete];
    [aCoder encodeDouble:_collectionCount forKey:kFinderDetailModelCollectionCount];
    [aCoder encodeObject:_addUser forKey:kFinderDetailModelAddUser];
    [aCoder encodeObject:_articleType forKey:kFinderDetailModelArticleType];
    [aCoder encodeDouble:_addTime forKey:kFinderDetailModelAddTime];
    [aCoder encodeObject:_updateUser forKey:kFinderDetailModelUpdateUser];
    [aCoder encodeObject:_smallImage forKey:kFinderDetailModelSmallImage];
    [aCoder encodeObject:_articleTitle forKey:kFinderDetailModelArticleTitle];
    [aCoder encodeBool:_articleStatus forKey:kFinderDetailModelArticleStatus];
    [aCoder encodeBool:_top forKey:kFinderDetailModelTop];
    [aCoder encodeBool:_like forKey:kFinderDetailModelLike];
}

- (id)copyWithZone:(NSZone *)zone
{
    FinderDetailModel *copy = [[FinderDetailModel alloc] init];
    
    if (copy) {

        copy.internalBaseClassIdentifier = self.internalBaseClassIdentifier;
        copy.topCount = self.topCount;
        copy.articleContet = [self.articleContet copyWithZone:zone];
        copy.updateTime = self.updateTime;
        copy.delete = self.delete;
        copy.isDelete = self.isDelete;
        copy.collectionCount = self.collectionCount;
        copy.addUser = [self.addUser copyWithZone:zone];
        copy.articleType = [self.articleType copyWithZone:zone];
        copy.addTime = self.addTime;
        copy.updateUser = [self.updateUser copyWithZone:zone];
        copy.smallImage = [self.smallImage copyWithZone:zone];
        copy.articleTitle = [self.articleTitle copyWithZone:zone];
        copy.articleStatus = self.articleStatus;
        copy.top = self.top;
        copy.like = self.like;
    }
    
    return copy;
}


@end
